<?php
    define(SEPARATE, '/');

    cpheader();

    echo '<script src="static/js/calendar.js"></script>';
    echo '<div class="floattop"><div class="itemtitle"><h3>视频列表</h3><ul class="tab1">';
    echo '</ul></div>';
    echo '<div class="itemtitle">';
    /*echo '<form action="" method="post">';
    echo '视频名称：<input type="text" class="txt" name="video_name" value="" style="width: 108px; margin-left: 5px;">&nbsp;&nbsp;';
    echo '开始时间：<input type="text" class="txt" name="start_time" value="" style="width: 108px; margin-left: 5px;" onclick="showcalendar(event, this)">&nbsp;&nbsp;';
    echo '结束时间：<input type="text" class="txt" name="end_time" value="" style="width: 108px; margin-left: 5px;" onclick="showcalendar(event, this)">';
    echo '&nbsp;&nbsp;&nbsp;&nbsp;<input type="submit" class="btn" value="搜索"></form>';*/
    echo '</div><br><br>';

    if(!isset($operation) || empty($operation)){

        /*$from_time = $_POST['start_time'];
        $end_time = $_POST['end_time'];
        $video_name = $_POST['video_name'];*/

        if(!empty($_GET['id'])){
            $v_id = $_GET['id'];
        }
        $totalRow = C::t('home_video_view')->get_view_num($v_id);
        $pageSize = 5;
        $totalPage = ceil($totalRow / $pageSize);
        if($_GET['p'] == ''){
            $currentPage = 1;
        }else{
            $currentPage = $_GET['p'];
        }
        $start = ($currentPage - 1) * $pageSize;
        $re = C::t('home_video_view')->get_all_view(0, $start, $pageSize);

        $str = '';
        for ($i=1; $i <= $totalPage; $i++) {
            if($currentPage != $i)
                $str .= '<a href="admin.php?action=viewinfo&p='.$i.'"><span style="margin:10px;">'.$i.'</span></a>';
            else
                $str .= '<span style="margin:10px;">'.$i.'</span>';
        }

        if(!empty($re)){
            echo '<table border="3" width="80%">';
            echo '<tr>';
            echo '<th style="text-align:center;">视频图片</th>';
            echo '<th style="text-align:center;">视频名称</th>';
            echo '<th style="text-align:center;">观看会员</th>';
            echo '<th style="text-align:center;">观看时间</th>';
            echo '<th style="text-align:center;">操作</th>';
            foreach($re as $val){
                echo '<tr>';
                echo '<td align="center" style="padding:10px;"><img src="'.$val['v_image'].'" style="height:50px;"></td>';
                echo '<td align="center" style="padding:15px;">'.$val['v_name'].'</td>';
                echo '<td align="center" style="padding:15px;">'.$val['username'].'</td>';
                echo '<td align="center" style="padding:15px;">'.date('Y-m-d H:i:s',$val['view_time']).'</td>';
                echo '<td align="center" style="padding:15px;"><a href="admin.php?action=viewinfo&operation=del&id='.$val['id'].'" style="color:red;">删除</a>';
                echo '</td>';
                echo '</tr>';
            }
            echo '<tr><td colspan="11" align="center">'.$str.'</td></tr></table>';
        }else{
            echo '暂无观看记录';
        }
    }elseif($operation == 'del' && $_GET['id'] != ''){
        if(!is_numeric($_GET['id'])){
            echo '<script type="text/javascript">alert("非法参数");</script>';
        }else{
            $info = C::t('home_video_view')->get_view_by_id($_GET['id']);
            if(empty($info)){
                echo '<script type="text/javascript">alert("非法参数");</script>';
            }else{
                C::t('home_video_view')->del_view($_GET['id']);
                echo '<script type="text/javascript">alert("删除成功");';
                echo 'window.location="'.ADMINSCRIPT.'?action=viewinfo";';
                echo '</script>';
            }
        }
    }

?>